package reading.common;

import reading.common.constant.NumConstant;
import reading.common.enums.RequestAuthEnum;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Project: haishu-news
 * Package: reading.common
 *
 * @author : txw
 * @version : v1.1
 * @since : 2018/10/15 14:50
 */
public class RequestAuthUtil {
    /**
     * 允许所有查询接口
     *
     * @return
     */
    public static Integer[] findAll() {
        RequestAuthEnum[] requestAuthEnums = RequestAuthEnum.values();
        List<Integer> list = Arrays.stream(requestAuthEnums).filter(requestAuthEnum -> requestAuthEnum.getValue() == 5 || requestAuthEnum.getValue() == 6).map(RequestAuthEnum::getValue).collect(Collectors.toList());
        Integer[] ints = new Integer[list.size()];
        return list.toArray(ints);
    }

    /**
     * 只能查询
     *
     * @return
     */
    public static Integer[] onlyFind() {
        RequestAuthEnum[] requestAuthEnums = RequestAuthEnum.values();
        List<Integer> list = Arrays.stream(requestAuthEnums).filter(requestAuthEnum -> requestAuthEnum.getValue() != 1 && requestAuthEnum.getValue() != 2).map(RequestAuthEnum::getValue).collect(Collectors.toList());
        Integer[] ints = new Integer[list.size()];
        return list.toArray(ints);
    }

    /**
     * 允许查询和详情
     *
     * @return
     */
    public static Integer[] onlyFindAndDetail() {
        RequestAuthEnum[] requestAuthEnums = RequestAuthEnum.values();
        List<Integer> list = Arrays.stream(requestAuthEnums).filter(requestAuthEnum -> {
            boolean auth = requestAuthEnum.getValue() == NumConstant.ONE || requestAuthEnum.getValue() == NumConstant.TWO || requestAuthEnum.getValue() == NumConstant.SEVEN;
            return !auth;
        }).map(RequestAuthEnum::getValue).collect(Collectors.toList());
        Integer[] ints = new Integer[list.size()];
        return list.toArray(ints);
    }

    /**
     * 只能创建表
     *
     * @return
     */
    public static Integer[] onlyCreate() {
        RequestAuthEnum[] requestAuthEnums = RequestAuthEnum.values();
        List<Integer> list = Arrays.stream(requestAuthEnums).filter(requestAuthEnum -> requestAuthEnum.getValue() != NumConstant.FIVE).map(RequestAuthEnum::getValue).collect(Collectors.toList());
        Integer[] ints = new Integer[list.size()];
        return list.toArray(ints);
    }
}
